package string;

/**
 * char charAt(int index)
 * 提取指定位置上的字符
 */
public class ChatAtDemo {
    public static void main(String[] args) {
        //            01234567890
        String str = "www.tedu.cn";

        char c = str.charAt(4);
        System.out.println(c);

        System.out.println("--------------------------");

        for (int i = 0;i < str.length();i++){
            c = str.charAt(i);
            System.out.println(c);
        }

        System.out.println("--------------------------");

        //检测回文
        String line = "上海自来水来自海上";
        /*
        char c1 = line.charAt(0);
        char c2 = line.charAt(line.length() - 1);

        c1 = line.charAt(1);
        c2 = line.charAt(line.length() - 2);

        c1 = line.charAt(3);
        c2 = line.charAt(line.length() - 3);

        c1 = line.charAt(4);
        c2 = line.charAt(line.length() - 4);
         */

        /*
        boolean check = true;
        for (int i=0;i<line.length()/2;i++){
            char c1 = line.charAt(i);
            char c2 = line.charAt(line.length()-1 - i);
            if (c1!=c2){
                System.out.println("不是回文");
                check = false;
                break;
            }
        }
        if (check){
            System.out.println("是回文");
        }
         */

        for (int i=0;i<line.length()/2;i++){
            char c1 = line.charAt(i);
            char c2 = line.charAt(line.length()-1 - i);
            if (c1!=c2){
                System.out.print("不");
                break;
            }
        }
        System.out.println("是回文");
    }
}










